package net.display;

import javax.servlet.http.HttpServletRequest;

import net.ko.controller.KObjectController;
import net.ko.displays.KObjectDisplay;
import net.ko.http.objects.KRequest;
import net.ko.http.views.KFieldControl;
import net.ko.http.views.KHtmlFieldControl;
import net.ko.http.views.KPageList;
import net.ko.kobject.KObject;
import net.ko.types.HtmlControlType;
import net.technics.ClassTechnics;

public class DisplayInscriptionTest extends KObjectDisplay {

	@Override
	public void beforeLoading(Class<? extends KObject> clazz, KPageList list, HttpServletRequest request) {
		Integer idPlan = Integer.valueOf(KRequest.GETPOST("id", request));
		super.beforeLoading(clazz, list, request);
	}

	@Override
	public KFieldControl getControl(KObject ko, String memberName, KObjectController koc, HttpServletRequest request) {
		KFieldControl fc = super.getControl(ko, memberName, koc, request);
		KHtmlFieldControl hfc = (KHtmlFieldControl) fc;
		switch (memberName) {
		case "idPlan":
			hfc.setValue(KRequest.GETPOST("id", request));
			hfc.setListMask("{libelle} -- {langage}");
			hfc.setFieldType(HtmlControlType.khcReadOnlyList);
			break;
		case "idUtilisateur":
			hfc.setValue(ClassTechnics.getActiveUser(request).getId() + "");
			break;
		case "idTypeDemande":
			hfc.setValue("1");
			break;
		default:
			break;
		}
		return fc;
	}

	@Override
	public KObjectController getKobjectController(KObjectController koc, HttpServletRequest request) {
		koc.getFieldController("description").setRequired(false);
		return super.getKobjectController(koc, request);
	}

}
